$(function () {
    var client_datagrid = $("#client_datagrid");
    var client_dialog = $("#client_dialog");
    var client_form = $("#client_form");
    var qo = $("#qo").val();
    var state;



    // client_datagrid客户列表初始化
    client_datagrid.datagrid({
        fit: true,
        url: "/client/Compensated",
        fitColumns: true,
        striped: true,
        pagination: true,
        singleSelect: true,
        rownumbers: true,
        pageSize: 10,
        pageList: [3, 5, 10, 15],
        toolbar: "#client_tb",
        sortName: "inputTime",
        sortOrder: "desc",
        columns: [[
            { field: 'id', width: 100, hidden:true},
            {title: '客户姓名', field: 'name', width: 100},
            {title: '年龄', field: 'age', width: 100},
            {
                title: '性别', field: 'gender', width: 100, formatter: function (value) {
                return value ? "男" : "女"
            }
            },
            {title: '电话号码', field: 'phone', width: 100},
            {title: '邮箱', field: 'email', width: 100},
            {title: '地址', field: 'address', width: 100},
            {title: '身份证', field: 'identityCard', width: 100}
        ]],
        onLoadSuccess: function (data) {

        },
        //新增
        border:false,
        cls:"table table-very table-basic"
    });

    // client_dialog:添加编辑对话框初始化
    client_dialog.dialog({
        title: '当前保单信息',
        width: '800px',
        height: '600px',
        closed: true
    });
    // client_dialog:END

    //响应函数集合对象
    var cmdObj = {

        // 客户高级查询
        query: function () {
            var row = client_datagrid.datagrid("getSelected");
            var keyword = $("#keyword").textbox("getValue");
            //回显
            // client_datagrid.datagrid("load", {
            //     keyword: keyword
            // });
            client_datagrid.datagrid({
                url:"/client/Compensated?keyword="+keyword
            });
        },

        checkbill: function () {
            //查看该用户的保单信息
            // 先获取该表格中被选中的一行
            var row = client_datagrid.datagrid("getSelected");

            if(row==null){
                $.messager.alert("温馨提示","请选择一个用户");
                return;
                       }
            //弹出对话框
            client_dialog.dialog("open");
            $.get("/insurancebill/checkWhichCompensate?id="+row.id ,function(data){
               console.log(data);
                $('#bill_dg').datagrid("loadData",data);
            })

        }
    }

    // 调用集合函数
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        // state = $(this).data("state");
        // console.log(state);
        cmdObj[cmd]();
    })

    //初始化表格
    $('#bill_dg').datagrid({
        // url:,
        fitColumns:true,
        columns:[[
            {field:'oddNumber',title:'保单流水号',width:100},
            {field:'vdate',title:'保单购买日期',width:100},
            {field:'limitYear',title:'有效年限',width:100},
            {field:'totalPrice',title:'投保金额',width:100},
            {field:'endDate',title:'截止日期',width:100}
        ]]

    });

});




